package org.example.controller;

import lombok.AllArgsConstructor;
import org.apache.ibatis.annotations.Param;
import org.example.dao.Result;
import org.example.dao.Song;
import org.example.service.SongService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@AllArgsConstructor
@RestController
@RequestMapping("/song")
public class SongController {
    private final SongService songService;

    //获取数据库中所有歌曲
    @GetMapping("/getSongList")
    public Result getSongList(Integer uid) {
        List<Song> songs = songService.getSongList(uid);
        if (songs != null) {
            return new Result(200, "获取成功", songs);
        } else {
            return new Result(404, "404 NotFind", null);
        }
    }

    @GetMapping("/search")
    public Result search(@Param("text") String text,@Param("uid") Integer uid) {
        List<Song> songs = songService.search(text,uid);
        if (songs != null) {
            return new Result(200, "获取成功", songs);
        } else {
            return new Result(404, "404 NotFind", null);
        }
    }
}
